#!/bin/bash
#author wjxiao
#date 2020072

# 1 判断当前是否root用户
if [ $(id -u) != "0" ]; then
 echo "error,not root user"
 exit 1
fi

# 2 判断opt是否存在

if [ ! -d /opt ]; then
 mkdir /opt && cd /opt

else
 cd /opt
fi

# 3 是否开始安装nginx(y/n)
read -p "是否开始安装nginx(y/n):" cho

case $cho in
y)
wget http://nginx.org/download/nginx-1.14.0.tar.gz
a=nginx-1.14.0
;;
n)
exit 1
;;
*)
echo "错误推出，请输入正常指令（y/n）"
exit 1
;;
esac

## 4 解压
if [ $? -eq 0 ]; then
 tar zxf $a.tar.gz 
else
 echo "下载有误"
 exit 1
fi


# 5
yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y

cd /opt/$a

./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module

make && make install

if [ $? -eq 0 ]; then
#安装成功$?输出为0时，创建nginx命令软链接。
 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
else
 echo "安装失败!!!"
fi

